<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.cinema.data.FilmInfo,com.cinema.data.Ticket,
com.cinema.data.User, java.util.List, query.DataQuery,
java.text.SimpleDateFormat" %>
<%@ page import="com.cinema.data.Adminusr" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta HTTP-EQUIV="Pragma" content="no-cache">
<meta HTTP-EQUIV="Expires" content="-1"> 
<title>Do An Mon Hoc</title>
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" title="default" />
</head>
<body>
<%
	Adminusr user = (Adminusr)session.getAttribute("adminuser");
	if(user == null)
		response.sendError(HttpServletResponse.SC_FORBIDDEN, "Unauthorized Access");
	boolean isAdmin = false;
	if(user.getGroupid() == 1)//Admin
		isAdmin = true;
	List<FilmInfo> currentFilm = (List<FilmInfo>)request.getAttribute("currentFilm");
	List<FilmInfo> comingFilm = (List<FilmInfo>)request.getAttribute("comingFilm");
	DataQuery query = new DataQuery();
	SimpleDateFormat dateformat = new SimpleDateFormat("dd/MM/yyyy");
	
%>
<!-- Start: page-top-outer -->
<div id="page-top-outer">    

<!-- Start: page-top -->
	<div id="page-top">
		<div class="clear"></div>

	</div>
<!-- End: page-top -->

</div>
<!-- End: page-top-outer -->
	
<div class="clear">&nbsp;</div>
 
<!--  start nav-outer-repeat................................................................................................. START -->
<div class="nav-outer-repeat"> 
<!--  start nav-outer -->
	<div class="nav-outer"> 
			<!--  start nav -->
			<div class="nav">
				<div class="table">
				
					<div class="nav-divider">&nbsp;</div>
									
					<%
				if(isAdmin){
%>			
									
					<ul class="current">

						<li><a href="cp.jsp"><b>Movie</b></a>
							<div class="select_sub show">
								<ul class="sub">									
									<li class="sub_show"><a href="cp.jsp">Add Movie</a></li>
									<li><a href="/ticket?pageid=2">Delete Movie</a></li>
									<li><a href="/ticket?pageid=1">Ticket</a></li>
								</ul>
							</div>
						</li>
					</ul>
					
					<div class="nav-divider">&nbsp;</div>
					
					<ul class="select">
						<li><a href="viewpage?id=1"><b>User Mangement</b></a>
						<div class="select_sub">
							<ul class="sub">
								<li><a href="viewpage?id=1">User List</a></li>
								<li><a href="viewpage?id=2">Add user</a></li>
								<li><a href="viewpage?id=3">Remove user</a></li>
							</ul>
						</div>
						</li>
					</ul>
<%
				}else{
%>
					<ul class="current">

						<li><a href="/ticket?pageid=1"><b>Movie</b></a>
							<div class="select_sub show">
								<ul class="sub">									
									<li class="sub_show"><a href="/ticket?pageid=1">Ticket</a></li>
								</ul>
							</div>
						</li>
					</ul>				
<%
				}
%>
					
					
					<div class="nav-divider">&nbsp;</div>
					
					<div class="clear"></div>
				</div>
				<div class="clear"></div>
			</div>
			<!--  start nav -->

	</div>
	<div class="clear"></div>
<!--  start nav-outer -->
</div>
<!--  start nav-outer-repeat................................................... END -->
 
 <div class="clear"></div>
 
<!-- start content-outer -->
<div id="content-outer">
<!-- start content -->
	<div id="content">


		<div id="page-heading"><h1>Ticket status</h1></div>


			<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
				<tr>
					<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
					<th class="topleft"></th>
					<td id="tbl-border-top">&nbsp;</td>
					<th class="topright"></th>
					<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
				</tr>
				<tr>
					<td id="tbl-border-left"></td>
					<td>
					<!--  start content-table-inner -->
						<div id="content-table-inner">
						
							<table border="0" width="100%" cellpadding="0" cellspacing="0">
								<tr valign="top">
									<td>
									
									
										<!--  start step-holder -->
										<div id="step-holder">
											<div class="step-dark-left"><a href="">Ticket List</a></div>
											<div class="step-dark-right">&nbsp;</div>
										</div>
										<!--  end step-holder -->
									
										<!-- start id-form -->
<%
	for(FilmInfo f: currentFilm){
		int i = 0;
		long fid = f.getFid();
%>
<h3><%= f.getFname() %></h3><br/>
<table border="2" width="1200px" cellpadding="3" cellspacing="0">
<tr style ="border : 2px;width: 100%; height: 20px;">
<td style="width : 100px; text-align: center;" bgcolor="yellow">ID</td>
<td style="width : 400px; text-align: center;" bgcolor="yellow">Date</td>
<td style="width : 200px; text-align: center;" bgcolor="yellow">Username</td>
<td style="width : 100px; text-align: center;" bgcolor="yellow">Quantity</td>
<td style="width : 100px; text-align: center;" bgcolor="yellow">Seat No.</td>
<%
		List<Ticket> ticketlist = query.getTicketList(fid);
		if(ticketlist != null){
			for(Ticket t: ticketlist){
				i++;
				long userid = t.getUsrid();
				User u = query.getUserByID(userid);
				int[] seatno = t.getSeatno();
%>
<tr>
	<td style="width : 100px; text-align: center;"><%=i %></td>
	<td style="width : 100px; text-align: center;"><%=dateformat.format(t.getBookday()) %></td>
	<td style="width : 100px; text-align: center;"><%=u.getFullname() %></td>
	<td style="width : 100px; text-align: center;"><%=t.getSeatQty() %></td>
	<td style="width : 100px; text-align: center;">
<%
				for(int k = 0; k < seatno.length; k++)
					out.print(seatno[k] + " ");
%>
	</td>
</tr>
<%
			}
		}
%>
</table><br /><br />
<%
	}
%>

<%
	for(FilmInfo f: comingFilm){
		long fid = f.getFid();
		int i = 0;
%>
<h3><%= f.getFname() %></h3><br/>
<table border="2" width="1200px" cellpadding="3" cellspacing="0">
<tr style ="border : 2px;width: 100%; height: 20px;">
<td style="width : 100px; text-align: center;" bgcolor="yellow">ID</td>
<td style="width : 400px; text-align: center;" bgcolor="yellow">Date</td>
<td style="width : 200px; text-align: center;" bgcolor="yellow">Username</td>
<td style="width : 100px; text-align: center;" bgcolor="yellow">Quantity</td>
<td style="width : 100px; text-align: center;" bgcolor="yellow">Seat No.</td>
<%
		List<Ticket> ticketlist = query.getTicketList(fid);
		if(ticketlist != null){
			for(Ticket t: ticketlist){
				i++;
				long userid = t.getUsrid();
				User u = query.getUserByID(userid);
				int[] seatno = t.getSeatno();
%>
<tr style ="border : 2px;width: 100%; height: 20px;">
	<td style="width : 100px; text-align: center;"><%=i %></td>
	<td style="width : 100px; text-align: center;"><%=dateformat.format(t.getBookday()) %></td>
	<td style="width : 100px; text-align: center;"><%=u.getFullname() %></td>
	<td style="width : 100px; text-align: center;"><%=t.getSeatQty() %></td>
	<td style="width : 100px; text-align: center;">
<%
				for(int k = 0; k < seatno.length; k++)
					out.print(seatno[k] + " ");
%>
	</td>
</tr>
<%
			}
		}
%>
</table><br /><br />
<%
	}
%>
										<!-- end id-form  -->
									</td>
								</tr>
							</table>
						 
							<div class="clear"></div>
						</div>
						<!--  end content-table-inner  -->
					</td>
					<td id="tbl-border-right"></td>
				</tr>
				<tr>
					<th class="sized bottomleft"></th>
					<td id="tbl-border-bottom">&nbsp;</td>
					<th class="sized bottomright"></th>
				</tr>
			</table>
		</div>
	</div>
</div>
</body>
</html>